import re

class Options:
    valid_rgb = re.compile(r'^#([\dabcdef]{6})', re.IGNORECASE)

    def __init__(self):
        self.attributes = dict()


    def __getitem__(self, attr):
        return self.attributes[attr]

    def __setitem__(self, attr, value):
        self.attributes[attr] = value

    def __str__(self):
        return str(self.attributes.keys())

    def isValid(self):
        """
        Return false if required options are missing or
        some option is invalid
        """
        options = [ 'bg', 'bg_namespace', 'bg_class', 'bg_func',
                    'fg_namespace', 'fg_class', 'fg_func']

        for option in options:
            val = self.attributes[option]
            if val and not self.valid_rgb.match(val):
                return False

        for option in ['input', 'width', 'height', 'step']:
            if not self.attributes[option]:
                return False

        return True
